<template>
  <div class="page labelSet">
    <van-nav-bar left-arrow @click-left="$router.push('/labelSet');" :title="title" class="my-nav-bar" />
    <van-form @submit="handleSubmit" label-width="100px" style="margin: 0px 15px 15px">
      <van-cell-group inset style="margin: 0px;">
        <van-field label="标签名称" required v-model="formData.itemName" placeholder="请输入标签名称"
          :rules="[{ required: true }]" />

        <van-field name="itemType" required label="标签类型" :rules="[{ required: true }]">
          <template #input>
            <van-radio-group v-model="formData.itemType" direction="horizontal">
              <van-radio name="1">消耗品类</van-radio>
              <van-radio name="2">设备类</van-radio>
            </van-radio-group>
          </template>
        </van-field>

      </van-cell-group>
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit">提交</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
export default {

  data() {
    return {
      title: '标签设置',
      formData: {
        itemName: '',
        itemType: "1"
      }
    }
  },
  mounted() {

    if (this.$route.params.id) {
      this.formData = this.$route.params || {}
    }
    this.title = this.formData.id ? '编辑标签' : '新增标签'

  },
  methods: {
    handleSubmit() {
      this.$axios({
        url: `/meet/roomNeedItem/${this.formData.id ? "edit" : "add"}`,
        method: 'post',
        data: this.formData
      }).then(res => {
        this.$toast.success(res || '操作成功');
        this.$router.push('/labelSet');
      })
    }
  }
}

</script>
<style lang="less" scoped>
.labelSet {
  background: linear-gradient(180deg, #E5F2FF 0%, #FFFFFF 100%);
  backdrop-filter: blur(0px);
  // .my-nav-bar2 {
  //   background-color: #E5F2FF;
  // }
}
</style>